//
//  YSPForwardCell.swift
//  Weibo Demo
//
//  Created by 朴裕识 on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class YSPForwardCell: YSPStatusCell {
    
    override var statusModel: YSPStatus? {
        didSet {
            if let forwardStatus = statusModel?.retweeted_status {
                let text = forwardStatus.text!
                forwardContentLabel.text = "@\(forwardStatus.userInfoArray!.screen_name!): \(text)"
            }
        }
    }
    
    override func prepareUI() {
        super.prepareUI()
        contentView.addSubview(forwardContentLabel)
        contentView.addSubview(bgButton)
        //将bgButton放到最底部，不要遮住配图
        contentView.sendSubviewToBack(bgButton)
        
       
        
        //bgButtonu左上角对齐contentLabel的左下角
        bgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        //bgButton右下角对齐bottomView的右上角
        bgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        forwardContentLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bgButton, size: nil, offset: CGPoint(x: 8, y: 8))
        /// 被转发微博文本label宽度
        contentView.addConstraint(NSLayoutConstraint(item: forwardContentLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))

        // 转发微博配图
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardContentLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        
        // 获取微博配图视图的宽高约束
        // 注意: 设置约束的时候需要设置 size， 不然框架不会添加宽高约束,拿不到宽高约束
        pictureViewWidthCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }


    //MARK: - 懒加载
    private lazy var forwardContentLabel: UILabel = {
       let label = UILabel(fontColor: UIColor.blackColor(), size: 14)
       
        label.numberOfLines = 0
       return label
    }()

    private lazy var bgButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.95, alpha: 1)
        return button
    }()

}
